﻿using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;
using System.Text;
using System.Web.Services;

public partial class admin_edit_newcl_rent : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        Session["p_id"] = Request.QueryString["id"].ToString();
        Label67.Visible = false;
        Label67.Text = Session["p_id"].ToString();
        if (Page.IsPostBack == true)
        {
        }
        else
        {

            SqlConnection conn = null;
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
            conn.Open();

            SqlCommand cmd = new SqlCommand("select * from  property_rent where c_id='" + Session["p_id"].ToString() + "'", conn);
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {

              // DropDownList52.Items.FindByValue(dr["c_type"].ToString()).Selected = true;
                TextBox55.Text = dr["custom_ctype"].ToString();
                //     DropDownList15.Items.FindByValue(dr["agent_name"].ToString()).Selected = true;
                 //DropDownList31.Items.FindByValue(dr["property"].ToString()).Selected = true;
                DropDownList31.Text = dr["property"].ToString();
                DropDownList52.Text = dr["c_type"].ToString();
                TextBox50.Text = dr["fname"].ToString();
                txtlname1.Text = dr["lname"].ToString();

                TextBox22.Text = dr["email_id"].ToString();
                TextBox21.Text = dr["phone"].ToString();
                TextBox18.Text = dr["h_no"].ToString();
                TextBox19.Text = dr["street"].ToString();
                TextBox23.Text = dr["nghr"].ToString();
                TextBox20.Text = dr["zip"].ToString();
                TextBox24.Text = dr["country"].ToString();
                TextBox25.Text = dr["city"].ToString();
                TextBox26.Text = dr["street1"].ToString();
                TextBox27.Text = dr["nghr1"].ToString();
                TextBox36.Text = dr["state1"].ToString();
                TextBox29.Text = dr["country1"].ToString();
                TextBox37.Text = dr["zip1"].ToString();
                TextBox3.Text = dr["f_room"].ToString();

                TextBox4.Text = dr["f_floor"].ToString();
                TextBox30.Text = dr["to_"].ToString();
                txtBalconies.Text = dr["balconies"].ToString();
                TextBox6.Text = dr["balconies_value"].ToString();
                //sDropDownList46.Items.FindByValue(dr["balconies_size"].ToString()).Selected = true;

                txtBalconies0.Text = dr["balconies0"].ToString();
                TextBox48.Text = dr["balconies_value1"].ToString();

                //  DropDownList47.Items.FindByValue(dr["balconies_size1"].ToString()).Selected = true;
                // DropDownList50.Items.FindByValue(dr["g_floor"].ToString()).Selected = true;
                TextBox52.Text = dr["cust_gfloor"].ToString();
                TextBox34.Text = dr["to_room1"].ToString();

                // DropDownList48.Items.FindByValue(dr["storage"].ToString()).Selected = true;
                // DropDownList16.Items.FindByValue(dr["ac"].ToString()).Selected = true;

                TextBox33.Text = dr["custom_ac"].ToString();

                //DropDownList32.Items.FindByValue(dr["saferoom"].ToString()).Selected = true;

                TextBox38.Text = dr["cust_saferoom"].ToString();
                TextBox31.Text = dr["no_of_resident"].ToString();
                TextBox9.Text = dr["budget"].ToString();
                // DropDownList33.Items.FindByValue(dr["type_budget"].ToString()).Selected = true;
                //DropDownList7.Items.FindByValue(dr["p_size"].ToString()).Selected = true;
                TextBox53.Text = dr["p_size_sign"].ToString();
                // DropDownList18.Items.FindByValue(dr["furniture"].ToString()).Selected = true;


                TextBox39.Text = dr["cust_furn"].ToString();
                TextBox12.Text = dr["entering_date"].ToString();
                TextBox46.Text = dr["roommate"].ToString();

                TextBox14.Text = dr["n_of_roommate"].ToString();
                // DropDownList10.Items.FindByValue(dr["guarantee"].ToString()).Selected = true;
                TextBox40.Text = dr["cust_guarantee"].ToString();
                //DropDownList49.Items.FindByValue(dr["elevator"].ToString()).Selected = true;
                TextBox51.Text = dr["cust_elevator"].ToString();
                // DropDownList9.Items.FindByValue(dr["voucher"].ToString()).Selected = true;
                TextBox41.Text = dr["cust_voucher"].ToString();
                //DropDownList13.Items.FindByValue(dr["prop_cond"].ToString()).Selected = true;
                TextBox42.Text = dr["cust_prop_cond"].ToString();
                //DropDownList12.Items.FindByValue(dr["animals"].ToString()).Selected = true;
                TextBox43.Text = dr["cust_animals"].ToString();
                // DropDownList11.Items.FindByValue(dr["smokers"].ToString()).Selected= true;

                TextBox44.Text = dr["cust_smoker"].ToString();
                TextBox32.Text = dr["occupation"].ToString();
                TextBox60.Text = dr["a_hrs"].ToString();

                TextBox7.Text = dr["parking"].ToString();
                TextBox45.Text = dr["custparking"].ToString();

                TextBox13.Text = dr["comments"].ToString();











            }
        }
    }




    protected void Cancel_Click(object sender, System.EventArgs e)
    {
        //btnSave_Student.Visible = true;
    }


    protected void ok(object sender, System.EventArgs e)
    {

    }

    protected void Save_Click(object sender, System.EventArgs e)
    {


        string cat = null;
        cat = DropDownList1.SelectedValue;
        SqlConnection conn = null;
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();


        SqlCommand cmd = new SqlCommand("update property_rent set c_type=@c_type,custom_ctype=@custom_ctype, agent_name=@agent_name,property=@property,fname=@fname,lname=@lname,email_id=@email_id, phone=@phone, h_no=@h_no, street=@street, nghr=@nghr,  zip=@zip,country= @country, city=@city, street1=@street1, nghr1=@nghr1, state1=@state1, country1=@country1, zip1=@zip1, f_room=@f_room, f_floor=@f_floor,to_=@to_,  balconies=@balconies, balconies_value=@balconies_value,  balconies_size=@balconies_size,  balconies0=@balconies0, balconies_value1=@balconies_value1, balconies_size1=@balconies_size1,g_floor=@g_floor,cust_gfloor=@cust_gfloor, to_room1=@to_room, storage=@storage,ac=@ac, custom_ac=@custom_ac,saferoom=@saferoom, cust_saferoom=@cust_saferoom, no_of_resident=@no_of_resident, budget=@budget, type_budget=@type_budget, p_size=@p_size,p_size_sign=@p_size_sign, furniture=@furniture, cust_furn=@cust_furn, entering_date=@entering_date,roommate=@roommate, n_of_roommate=@n_of_roommate, guarantee=@guarantee, cust_guarantee=@cust_guarantee,elevator=@elevator,cust_elevator=@cust_elevator, voucher=@voucher,  cust_voucher=@cust_voucher, prop_cond=@prop_cond, cust_prop_cond=@cust_prop_cond,animals=@animals, cust_animals=@cust_animals,  smokers=@smokers, cust_smoker=@cust_smoker, occupation=@occupation, a_hrs=@a_hrs, parking=@parking, custparking=@custparking, north=@north, p_south=@p_south,  p_east=@p_east,  p_west=@p_west, smart_house=@smart_house,  alarm=@alarm , bars=@bars, handicap=@handicap,guard=@guard,  gym=@gym, jacuzie=@jacuzie, pool=@pool,  check_custom=@check_custom,  custom=@custom,comments=@comments,status1=@status1,  adding_date=@adding_date, adding_by= @adding_by where c_id='" + Request.QueryString["id"].ToString() + "'", conn);

        cmd.Parameters.AddWithValue("@c_type", DropDownList52.SelectedValue);
        cmd.Parameters.AddWithValue("@custom_ctype", TextBox55.Text);
        cmd.Parameters.AddWithValue("@agent_name", DropDownList15.SelectedValue);
        cmd.Parameters.AddWithValue("@property", DropDownList31.SelectedValue);


        cmd.Parameters.AddWithValue("@fname", TextBox50.Text);
        cmd.Parameters.AddWithValue("@lname", txtlname1.Text);

        cmd.Parameters.AddWithValue("@email_id", TextBox22.Text);
        cmd.Parameters.AddWithValue("@phone", TextBox21.Text);
        cmd.Parameters.AddWithValue("@h_no", TextBox18.Text);
        cmd.Parameters.AddWithValue("@street", TextBox19.Text);
        cmd.Parameters.AddWithValue("@nghr", TextBox23.Text);
        cmd.Parameters.AddWithValue("@zip", TextBox20.Text);
        cmd.Parameters.AddWithValue("@country", TextBox24.Text);
        cmd.Parameters.AddWithValue("@city", TextBox25.Text);
        cmd.Parameters.AddWithValue("@street1", TextBox26.Text);
        cmd.Parameters.AddWithValue("@nghr1", TextBox27.Text);
        cmd.Parameters.AddWithValue("@state1", TextBox36.Text);
        cmd.Parameters.AddWithValue("@country1", TextBox29.Text);
        cmd.Parameters.AddWithValue("@zip1", TextBox37.Text);
        cmd.Parameters.AddWithValue("@f_room", TextBox3.Text);

        cmd.Parameters.AddWithValue("@f_floor", TextBox4.Text);
        cmd.Parameters.AddWithValue("@to_", TextBox30.Text);
        cmd.Parameters.AddWithValue("@balconies", txtBalconies.Text);
        cmd.Parameters.AddWithValue("@balconies_value", TextBox6.Text);
        cmd.Parameters.AddWithValue("@balconies_size", DropDownList46.SelectedValue);

        cmd.Parameters.AddWithValue("@balconies0", txtBalconies0.Text);
        cmd.Parameters.AddWithValue("@balconies_value1", TextBox48.Text);

        cmd.Parameters.AddWithValue("@balconies_size1", DropDownList47.SelectedValue);
        cmd.Parameters.AddWithValue("@g_floor", DropDownList50.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_gfloor", TextBox52.Text);
        cmd.Parameters.AddWithValue("@to_room", TextBox34.Text);

        cmd.Parameters.AddWithValue("@storage", DropDownList48.SelectedValue);
        cmd.Parameters.AddWithValue("@ac", DropDownList16.SelectedValue);

        cmd.Parameters.AddWithValue("@custom_ac", TextBox33.Text);

        cmd.Parameters.AddWithValue("@saferoom", DropDownList32.SelectedValue);

        cmd.Parameters.AddWithValue("@cust_saferoom", TextBox38.Text);
        cmd.Parameters.AddWithValue("@no_of_resident", TextBox31.Text);
        cmd.Parameters.AddWithValue("@budget", TextBox9.Text);
        cmd.Parameters.AddWithValue("@type_budget", DropDownList33.SelectedValue);
        cmd.Parameters.AddWithValue("@p_size", DropDownList7.SelectedValue);
        cmd.Parameters.AddWithValue("@p_size_sign", TextBox53.Text);
        cmd.Parameters.AddWithValue("@furniture", DropDownList18.SelectedValue);


        cmd.Parameters.AddWithValue("@cust_furn", TextBox39.Text);
        cmd.Parameters.AddWithValue("@entering_date", TextBox12.Text);
        cmd.Parameters.AddWithValue("@roommate", TextBox46.Text);

        cmd.Parameters.AddWithValue("@n_of_roommate", TextBox14.Text);
        cmd.Parameters.AddWithValue("@guarantee", DropDownList10.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_guarantee", TextBox40.Text);
        cmd.Parameters.AddWithValue("@elevator", DropDownList49.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_elevator", TextBox51.Text);
        cmd.Parameters.AddWithValue("@voucher", DropDownList9.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_voucher", TextBox41.Text);
        cmd.Parameters.AddWithValue("@prop_cond", DropDownList13.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_prop_cond", TextBox42.Text);
        cmd.Parameters.AddWithValue("@animals", DropDownList12.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_animals", TextBox43.Text);
        cmd.Parameters.AddWithValue("@smokers", DropDownList11.Text);

        cmd.Parameters.AddWithValue("@cust_smoker", TextBox44.Text);
        cmd.Parameters.AddWithValue("@occupation", TextBox32.Text);
        cmd.Parameters.AddWithValue("@a_hrs", TextBox60.Text);

        cmd.Parameters.AddWithValue("@parking", TextBox7.Text);
        cmd.Parameters.AddWithValue("@custparking", TextBox45.Text);


        cmd.Parameters.AddWithValue("@north", CheckBox9.Checked);
        cmd.Parameters.AddWithValue("@p_south", CheckBox10.Checked);
        cmd.Parameters.AddWithValue("@p_east", CheckBox11.Checked);
        cmd.Parameters.AddWithValue("@p_west", CheckBox12.Checked);
        cmd.Parameters.AddWithValue("@smart_house", CheckBox1.Checked);
        cmd.Parameters.AddWithValue("@alarm ", CheckBox2.Checked);
        cmd.Parameters.AddWithValue("@bars", CheckBox3.Checked);
        cmd.Parameters.AddWithValue("@handicap", CheckBox4.Checked);
        cmd.Parameters.AddWithValue("@guard", CheckBox5.Checked);
        cmd.Parameters.AddWithValue("@gym", CheckBox6.Checked);
        cmd.Parameters.AddWithValue("@jacuzie", CheckBox7.Checked);
        cmd.Parameters.AddWithValue("@pool", CheckBox8.Checked);
        cmd.Parameters.AddWithValue("@check_custom", CheckBox13.Checked);
        cmd.Parameters.AddWithValue("@custom", TextBox5.Text);

        cmd.Parameters.AddWithValue("@comments", TextBox13.Text);

        cmd.Parameters.AddWithValue("@status1", "0");
        cmd.Parameters.AddWithValue("@adding_date", System.DateTime.Now);
        cmd.Parameters.AddWithValue("@adding_by", "admin");


        cmd.ExecuteNonQuery();


        Response.Redirect("propert_for_conf.aspx");




    }
    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("../admin.aspx");
    }
    protected void CheckBox13_CheckedChanged(object sender, System.EventArgs e)
    {
        // Label1.Visible = true;
        TextBox5.Visible = true;
    }
    protected void Button4_Click(object sender, System.EventArgs e)
    {

    }

    protected void Button5_Click(object sender, System.EventArgs e)
    {
        Label9.Visible = true;
        TextBox49.Visible = true;
    }
    protected void txtcreate_TextChanged(object sender, System.EventArgs e)
    {

    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "action")
        {

            //Label1.Text = "hello";
            int index = Convert.ToSByte(e.CommandArgument);

            GridViewRow row = GridView2.Rows[index];
            SqlDataAdapter adp = new SqlDataAdapter();
            SqlCommand cmd1 = new SqlCommand();
            DataSet ds = new DataSet();


            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

            con.Open();

            SqlCommand objectvalue = new SqlCommand("", con);
            cmd1.Connection = con;

            SqlCommand dmc = new SqlCommand("Delete from properties_rent where p_id='" + row.Cells[0].Text + "'", con);
            dmc.ExecuteNonQuery();

            // SqlCommand dmc = new SqlCommand("select p_id from properties where p_id='" + row.Cells[0].Text + "'", con);

            //dmc.ExecuteNonQuery();
            //  Session["p_id"] = row.Cells[0].Text;

            con.Close();
            // Response.Write(Session["p_id"]);
            // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

            Response.Redirect("report_property_for_rent.aspx");
            // con.Close();


        }




        if (e.CommandName == "view")
        {

            //Label1.Text = "hello";
            int index = Convert.ToSByte(e.CommandArgument);

            GridViewRow row = GridView2.Rows[index];
            SqlDataAdapter adp = new SqlDataAdapter();
            SqlCommand cmd1 = new SqlCommand();
            DataSet ds = new DataSet();


            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

            con.Open();

            SqlCommand objectvalue = new SqlCommand("", con);
            cmd1.Connection = con;



            SqlCommand dmc = new SqlCommand("select t_id from task where t_id='" + row.Cells[0].ToString() + "'", con);

            dmc.ExecuteNonQuery();
            Session["t_id"] = row.Cells[0].Text.ToString();

            con.Close();
            // Response.Write(Session["p_id"]);
            // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

            Response.Redirect("edit-task.aspx");
            // con.Close();


        }

    }

}